import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
    name: 'roundAndTruncate'
})
export class RoundAndTruncatemPipe implements PipeTransform {
    transform(value: any, round: any, isTruncate): any {
        if (isTruncate === true) {       // 保留小数round位，不四省五入
            const times = Math.pow(10, round);
            return parseInt(value * times + '', 10) / times;
        } else {                         // 保留小数round位，四省五入
            return parseFloat(value).toFixed(round);
        }
    }


}
